package dao

import (
	"hcy-api/structs/tables"
	"sys/global"
)

var RoleDB = new(roleRepository)

type roleRepository struct{}

func (r roleRepository) SelectRolesByUserId(userId int64) (li []tables.Role, err error) {
	err = global.DB.Raw("select * from sys_role where role_id in ( "+
		" select role_id from sys_map_user_role where user_id =? )", userId).Scan(&li).Error
	return
}

func (r roleRepository) FindAll(isOpen int) (li []*tables.Role, err error) {
	err = global.DB.Where("is_open =?", isOpen).Find(&li).Error
	return
}
